namespace :jq4r do
  desc "Install the necessary javascript files."
  task :install => :environment do
    require 'fileutils'
    
    plugins_dir = File.expand_path(RAILS_ROOT+'/vendor/plugins')
    jq4r_dir = File.join(plugins_dir, 'jq4r-0.2')

    cp File.join(jq4r_dir, 'javascripts', 'jquery-1.2.1.min.js'), File.join(RAILS_ROOT, 'public', 'javascripts', 'jquery.js')
    cp File.join(jq4r_dir, 'javascripts', 'jquery.form-min.js'), File.join(RAILS_ROOT, 'public', 'javascripts', 'jquery-form.js')
    mkdir_p "#{RAILS_ROOT}/public/javascripts/jquery-ui"
    cp File.join(jq4r_dir, 'javascripts', 'jquery.dimensions-min.js'), File.join(RAILS_ROOT, 'public', 'javascripts', 'jquery-ui', 'jquery.dimensions.js')
    cp File.join(jq4r_dir, 'javascripts', 'ui.draggable-min.js'), File.join(RAILS_ROOT, 'public', 'javascripts', 'jquery-ui', 'ui.draggable.js')
    cp File.join(jq4r_dir, 'javascripts', 'ui.mouse-min.js'), File.join(RAILS_ROOT, 'public', 'javascripts', 'jquery-ui', 'ui.mouse.js')
    cp File.join(jq4r_dir, 'javascripts', 'ui.resizable-min.js'), File.join(RAILS_ROOT, 'public', 'javascripts', 'jquery-ui', 'ui.resizable.js')    
    cp File.join(jq4r_dir, 'javascripts', 'ui.dialog-min.js'), File.join(RAILS_ROOT, 'public', 'javascripts', 'jquery-ui', 'ui.dialog.js')
    cp File.join(jq4r_dir, 'javascripts', 'ui.shadow-min.js'), File.join(RAILS_ROOT, 'public', 'javascripts', 'jquery-ui', 'ui.shadow.js')
    cp_r(File.join(jq4r_dir, 'themes'), File.join(RAILS_ROOT, 'public', 'stylesheets', 'jquery-ui-themes'))
    cp File.join(jq4r_dir, 'javascripts', 'jq4r.js'), File.join(RAILS_ROOT, 'public', 'javascripts', 'jq4r.js')
    cp File.join(jq4r_dir, 'stylesheets', 'jq4r.css'), File.join(RAILS_ROOT, 'public', 'stylesheets', 'jq4r.css')
  end
end